// 策略模式
import { ElMessage } from "element-plus"
class Validator {
  constructor(cache) {
    this.cache = cache
  }
  check() {
    return this.cache.every((item) => {
      console.log(item.fn)
      let { msg, type } = item.options
      let flag = item.fn(item.options)
      if (flag && msg) {
        msg instanceof Function
          ? msg()
          : ElMessage({
              message: msg || "校验失败",
              type: type || "warning",
              showClose: true,
            })
      }
      return flag
    })
  }
}

export default Validator
